<template>
  <el-card shadow="never" class="aui-card--fill managementWrapper">
    <div class="mod-sys__user">
      <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataList()"
      >
        <el-form-item>
          <el-input
            v-model="dataForm.material_serial"
            placeholder="物料编号"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="dataForm.name" placeholder="物料名称"></el-input>
        </el-form-item>
        <!-- <el-form-item>
              <ren-dept-tree v-model="dataForm.deptId" :placeholder="$t('dept.title')" :query="true"></ren-dept-tree>
            </el-form-item> -->
        <el-form-item>
          <el-button @click="getDataList()">搜索</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="toAdd()">创建物料</el-button>
        </el-form-item>
      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        border
        @selection-change="dataListSelectionChangeHandle"
        @sort-change="dataListSortChangeHandle"
        style="width: 100%"
      >
        <el-table-column
          type="index"
          label="序号"
          header-align="center"
          align="center"
          width="80"
        ></el-table-column>
        <el-table-column
          prop="material_serial"
          label="物料编号"
          header-align="center"
          align="center"
          width="241"
        ></el-table-column>
        <el-table-column prop="name" label="物料" width="300">
          <template slot-scope="scope">
            <div class="verticalCenter prodBox">
              <div
                class="imgBox"
                @click="
                  handlePreview(
                    scope.row.pics.length > 0 ? scope.row.pics[0] : ''
                  )
                "
              >
                <img
                  :src="scope.row.pics.length > 0 ? scope.row.pics[0] : ''"
                />
              </div>
              <div class="rightBox">
                {{ scope.row.name }}
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="specifications_model"
          label="规格型号"
          header-align="center"
          align="center"
          width="240"
        ></el-table-column>
        <el-table-column
          prop="material_type"
          label="物料类别"
          header-align="center"
          align="center"
          sortable="custom"
          min-width="130"
        >
          <template slot-scope="scope">
            {{
              $getDictLabel('material_type', String(scope.row.material_type))
            }}
          </template>
        </el-table-column>
        <el-table-column
          prop="material_attr"
          label="物料属性"
          header-align="center"
          align="center"
          sortable="custom"
          min-width="130"
        >
          <template slot-scope="scope">
            {{
              $getDictLabel('material_attr', String(scope.row.material_attr))
            }}
          </template>
        </el-table-column>
        <el-table-column
          prop="operator_user"
          label="最后操作人"
          header-align="center"
          align="center"
          min-width="130"
        ></el-table-column>
        <el-table-column
          prop="operator_time"
          label="最后操作时间"
          sortable="custom"
          header-align="center"
          align="center"
          width="180"
        ></el-table-column>
        <el-table-column
          :label="$t('handle')"
          fixed="right"
          header-align="center"
          align="center"
          width="150"
        >
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="toAdd(scope.row)"
              >编辑</el-button
            >
            <el-button type="text" size="small" @click="toDetail(scope.row)"
              >详情</el-button
            >
            <el-button
              type="text"
              size="small"
              @click="deleteHandle(scope.row.id)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="num"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle"
      >
      </el-pagination>
      <el-dialog :visible.sync="dialogVisible" title="查看">
        <img width="100%" :src="dialogImageUrl" class="avatar" />
      </el-dialog>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import { addDynamicRoute } from '@/router'
//   import AddOrUpdate from './user-add-or-update'
export default {
  mixins: [mixinViewModule],
  components: {
    // AddOrUpdate
  },
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/material',
        getDataListIsPage: true,
        deleteURL: '/material_delete',
        deleteIsBatch: true,
      },
      dataForm: {
        name: '',
        material_serial: '',
      },
    }
  },
  methods: {
    toDetail(row) {
      const routeParams = {
        routeName: `${this.$route.name}__${row.id}`,
        title: `${this.$route.meta.title} - 详情`,
        path: 'product/material-detail',
        params: {
          id: row.id,
        },
      }
      addDynamicRoute(routeParams, this.$router)
    },
    toAdd(row) {
      const des = row ? '编辑' : '新增'
      const type = row ? 'edit' : 'add'
      const routeParams = {
        routeName: `${this.$route.name}__${type}`,
        title: `${this.$route.meta.title} - ${des}`,
        path: 'product/material-add',
        params: {
          id: row?.id || '',
        },
      }
      addDynamicRoute(routeParams, this.$router)
    },
  },
}
</script>

<style lang="scss" scoped>
.managementWrapper {
  .prodBox {
    padding-left: 6px;
    .imgBox {
      width: 64px;
      height: 64px;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .rightBox {
      margin-left: 14px;
      text-align: left;
      .top {
        max-width: 200px;
        margin-bottom: 6px;
      }
      .bottom {
        color: $mainColor;
      }
    }
  }
}
</style>

<!-- <style lang="scss" scoped>
  ::v-deep .el-table .cell {
    line-height: 19px !important;
  }
  </style> -->
